<?php
/*
 * Funktion generiert einen Shortcut, wenn @var $shortcut leer ist.
 */
function MakeShortcut($series, $shortcut)
{
    if($shortcut == null || $shortcut == '')
    {
        if(strlen($series) <= 8)
        {
            return $series;
        }
        else
        {
            $series    = preg_replace('/[^a-zA-Z0-9äöüÄÖÜß]/', ' ', $series); // TODO: Sonderzeichenregelung?
            $shortcuts = explode(' ', $series);
            foreach($shortcuts as $s)
            {
                if(ctype_digit($s))
                {
                    $shortcut .= '_' . $s; // _ + komplette Zahl
                }
                else
                {
                    $shortcut  .= substr($s, 0, 1); // erster Buchstabe des Einzelwortes
                }
            }
            return $shortcut;
        }
    }
    return $shortcut;
}

/*
 * Rechte überprüfen (LIGA)
 */
function HasAccessToLeague($jid, $league_id)
{
    require_once('Database/Database.php');
    $db = new Database();
    $db->Connect();
    $admin = $db->Select('Admins', 'JID = ' . $jid);

    $access = false;
    if($admin)
    {
        if($admin[0]->Super-Admin != 0)
        {
            $access = true;
        }
        else
        {
            $adm_leagues = explode(',', $admin[0]->Leagues);
            foreach($adm_leagues as $league)
            {
                if($league == $league_id)
                {
                    $access = true;
                    return $access;
                }
            }
        }
    }
    $db->Disconnect();
    return $access;  
}

/*
 * Rechte überprüfen (SERIE)
 */
function HasAccessToSeries($jid, $series_id)
{
    require_once('Database/Database.php');
    $db = new Database();
    $db->Connect();
    $admin = $db->Select('Admins', 'JID = ' . $jid);

    $access = false;
    if($admin)
    {
        if($admin[0]->Super-Admin != 0)
        {
            $access = true;
        }
        else
        {
            $adm_series = explode(',', $admin[0]->Series);
            foreach($adm_series as $series)
            {
                if($series == $series_id)
                {
                    $access = true;
                    return $access;
                }
            }
        }
    }
    $db->Disconnect();
    return $access;   
}
?>           